Skip to content

截图并保存成文件 - Capture

函数简介

抓取指定区域的图像并保存为文件,图片大小为 x2-x1, y2-y1。

接口名称

Capture

DLL调用

int Capture(long ola, int x1, int y1, int x2, int y2, string file);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x1整数型区域的左上X坐标。
y1整数型区域的左上Y坐标。
x2整数型区域的右下X坐标。
y2整数型区域的右下Y坐标。
file字符串保存的文件名,支持 .bmp、.png、.jpg 格式,使用相对路径时保存在SetPath设置的目录下。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 截取绑定窗口客户区并保存为文件
int ret = ola.Capture(0, 0, 0, 0, "screenshot.png");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 截取绑定窗口客户区并保存为文件
int ret = ola.Capture(0, 0, 0, 0, "screenshot.png");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 截取绑定窗口客户区并保存为文件
ret = ola.Capture(0, 0, 0, 0, "screenshot.png")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
// 截取绑定窗口客户区并保存为文件
int ret = ola.Capture(0, 0, 0, 0, "screenshot.png");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 截取绑定窗口客户区并保存为文件
ret := ola.Capture(0, 0, 0, 0, "screenshot.png")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 截取绑定窗口客户区并保存为文件
let ret = ola.capture(0, 0, 0, 0, "screenshot.png");
cpp
var ola = com("OlaPlug.OlaSoft")
// 截取绑定窗口客户区并保存为文件
var ret = ola.Capture(0, 0, 0, 0, "screenshot.png")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 截取绑定窗口客户区并保存为文件
ret = ola.Capture(0, 0, 0, 0, "screenshot.png")
text
.局部变量 ola, OLAPlug
ola.创建 ()
' 截取绑定窗口客户区并保存为文件
ret = ola.Capture(0, 0, 0, 0, "screenshot.png")
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 截取绑定窗口客户区并保存为文件
var ret = ola.Capture(0, 0, 0, 0, "screenshot.png");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 截取绑定窗口客户区并保存为文件
整数 ret = ola.Capture(0, 0, 0, 0, "screenshot.png")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 截取绑定窗口客户区并保存为文件
int ret = ola.Capture(0, 0, 0, 0, "screenshot.png");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int ret = Capture(instance, 0, 0, 0, 0, "screenshot.png");
csharp
long instance = CreateCOLAPlugInterFace();
int ret = Capture(instance, 0, 0, 0, 0, "screenshot.png");
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ret = Capture(instance, 0, 0, 0, 0, "screenshot.png")

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
格式文件后缀名决定保存格式。
保存前请确保目标目录存在保存前请确保目标目录存在。
与 GetScreenDataPtr 区别Capture 将截图 保存为文件 并返回成功/失败;需要 内存图像句柄 供后续识别、找色等处理时,请使用 GetScreenDataPtr